package Reflect;

import java.lang.reflect.Constructor;

public class Reflect3 {
    public static void main(String[] args) throws Exception {
        Class personClass = Person.class;
        Constructor constructor = personClass.getConstructor(String.class, int.class);
        System.out.println(constructor);
        //创建一个Constructor对象
        //创建对象
        Object person = constructor.newInstance("张三", 23);
        System.out.println(person);
        //Person{name='张三', age=23, a='null'}
        System.out.println("===============");
        Constructor constructor1 = personClass.getConstructor();
        Object person1 = constructor1.newInstance();
        System.out.println(person1);
        //Person{name='null', age=0, a='null'}

        Object o = personClass.newInstance();
        System.out.println(o);
        //打印和上面的一样的结果
        //Person{name='null', age=0, a='null'}
    }
}
